package com.eazy.lkv2.core.analysis.weather;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.eazy.lkv2.core.analysis.weather.support.Weather;
import com.eazy.lkv2.core.data.BaseData;

@Component
public class WeatherAnalysis {

	private Map<String, WeatherStrategy> strategies = new HashMap<String, WeatherStrategy>();
	
	@PostConstruct
	public void init() {
		strategies.put("weather", new Weather());
	}
	
	public void setStrategies(Map<String, WeatherStrategy> strategies) {
		this.strategies = strategies;
	}
	
	public BaseData take(String url) {
		String host = url;
		
		WeatherStrategy strategy = strategies.get(host);
		
		Assert.notNull(strategy, "地址格式不对, 或不支持该网站" + host);
		
		return strategy.take(url);
	}
}
